<!DOCTYPE html>
<html lang="en">
<head>
    <title>mqtt</title>
    <meta charset="UTF-8">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/paho-mqtt/1.0.1/mqttws31.min.js" type="text/javascript"></script>  
</head>
<body>

</body>
<script>
client = new Paho.MQTT.Client("0.0.0.0", Number(61623), "客户端ID");//建立客户端实例  
            client.connect({onSuccess:onConnect});//连接服务器并注册连接成功处理事件  
            function onConnect() {  
                console.log("onConnected");  
                client.subscribe("/topic_back");//订阅主题  
            }  
client.onConnectionLost = onConnectionLost;//注册连接断开处理事件  
client.onMessageArrived = onMessageArrived;//注册消息接收处理事件  
function onConnectionLost(responseObject) {  
    if (responseObject.errorCode !== 0) {  
        console.log("onConnectionLost:"+responseObject.errorMessage);  
        console.log("连接已断开");  
        }  
}  
function onMessageArrived(message) {  
    console.log("收到消息:"+message.payloadString);  
}  
//发送消息  
message = new Paho.MQTT.Message("hello");  
message.destinationName = "/topic";  
client.send(message);  
</script>

</html>